package com.yzion.demo_swipeback.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ClickUtils;
import com.yzion.baseapp.R;
import com.yzion.demo_swipeback.BaseSwipeBackFragment;
import com.yzion.demo_swipeback.PagerAdapter;

import java.util.ArrayList;
import java.util.List;


public class RecyclerSwipeBackFragment extends BaseSwipeBackFragment {

    private Toolbar mToolbar;

    private RecyclerView mRecy;
    private PagerAdapter mAdapter;

    public static RecyclerSwipeBackFragment newInstance() {
        RecyclerSwipeBackFragment fragment = new RecyclerSwipeBackFragment();
        return fragment;
    }

    @Override
    public View setContentView(@NonNull LayoutInflater inflater, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_swipe_back_recy, null);
        return view;
    }

    @Override
    public boolean isUseDefaultTitleBar() {
        return false;
    }

    @Override
    public View createCustomTitleBar() {
        View titleBarView = getLayoutInflater().inflate(R.layout.custom_title_bar_view, null);
        View btnBack = titleBarView.findViewById(R.id.btn_back);
        btnBack.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
            @Override
            public void onDebouncingClick(View v) {
                onBackPressed();
            }
        });
        return titleBarView;
    }


    @Override
    public void initView() {
        mRecy = findViewById(R.id.recy);
//        mDefaultToolbar = (Toolbar) findViewById(R.id.toolbar);
//        initToolbar(mDefaultToolbar);

        mAdapter = new PagerAdapter(getActivity());
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        mRecy.setLayoutManager(manager);
        mRecy.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener(new PagerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, View view) {
                if (mAddFragmentListener != null) {
                    mAddFragmentListener.onAddFragment(RecyclerSwipeBackFragment.this, FirstSwipeBackFragment.newInstance());
                }
            }
        });

        // Init Datas
        List<String> items = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            String item;
            item = "收藏 " + i;
            items.add(item);
        }
        mAdapter.setDatas(items);
    }

    @Override
    public void initData() {

    }


}
